package org.corolla.cloth.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage(value = "struts-default")
@Results({
          @Result(name = "input", type = "redirect", location = "/view/AccessoryChoose.jsp"),
          @Result(name = "success", type = "redirect", location = "pricesheetAction") })
@Namespace("/view")
@Action(value = "accessoryAction")
public class AccessoryAction extends ActionSupport {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private String            button;
    private String            buttonnum;
    private String            shoulder;
    private String            shouldernum;

    @Override
    public String execute() throws Exception {
        // 程序运行到execute()时，前面的验证都已经正确了
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();

        if (StringUtils.isNotBlank(this.getButton()) && StringUtils.isNotBlank(this.getButtonnum())
            && StringUtils.isNotBlank(this.getShoulder()) && StringUtils.isNotBlank(this.getShouldernum())) {
            session.setAttribute("button", this.getButton());
            session.setAttribute("buttonnum", this.getButtonnum());
            session.setAttribute("shoulder", this.getShoulder());
            session.setAttribute("shouldernum", this.getShouldernum());
            return SUCCESS;
        }
        return "input";
    }

    public String getButton() {
        return button;
    }

    public void setButton(String button) {
        this.button = button;
    }

    public String getButtonnum() {
        return buttonnum;
    }

    public void setButtonnum(String buttonnum) {
        this.buttonnum = buttonnum;
    }

    public String getShoulder() {
        return shoulder;
    }

    public void setShoulder(String shoulder) {
        this.shoulder = shoulder;
    }

    public String getShouldernum() {
        return shouldernum;
    }

    public void setShouldernum(String shouldernum) {
        this.shouldernum = shouldernum;
    }

}
